package controllers

import (
	"encoding/json"
	"fmt"
	"strconv"

	"gitee.com/wangxj0826/experiment-codes/service-pressure-test/service"
	"github.com/beego/beego/v2/core/logs"
	beego "github.com/beego/beego/v2/server/web"
)

type UserInfoController struct {
	beego.Controller
}

func (c *UserInfoController) Get() {
	userID := c.Ctx.Input.Param(":id")
	id, err := strconv.Atoi(userID)
	if err != nil {
		logs.Info("err: %v", err)
		c.Ctx.WriteString(fmt.Sprintf("err: %v", err))
		return
	}
	user, err := service.GetUserInfoSvc().GetUserByID(id)
	if err != nil {
		logs.Info("err: %v", err)
		c.Ctx.WriteString(fmt.Sprintf("err: %v", err))
		return
	}
	respBody, _ := json.Marshal(user)
	c.Ctx.WriteString(string(respBody))
}

func (c *UserInfoController) Post() {
	c.Ctx.WriteString("PostUserById")
}
